<?php
$config_name=$_GET['name'];
$row=Config::fetch_by_name($config_name);
if($row)
{
	eval(Common::define_var_from_array($row));
	if(isset($_POST['submit_value']))
	{
		$array=$_POST;
		unset($array['submit_value']);
		Config::save_by_name($config_name,$config_value_type,$_POST['config_content']);
		if($_POST['submit_value']=='Lưu & Đóng')
			Common::header_location(null,null,"$('#btn_close').trigger('click')");
		else
			Common::header_location(null,"popup.php?page=_config-update&name=$config_name");
	}
}
else
	Common::header_location(null,'error.php?code=404');
?>
<form method='post' class='form'>
	<label>
		<strong>Tên</strong>
		<input readonly="readonly" type='text' value='<?php echo $config_name;?>'/>
	</label>
	<label>
		<strong>Nội dung</strong>
		<?php
		switch($config_value_type)
		{
			case 1://textarea ckeditor Full
				?>
				<textarea class='editor' toolbar='Full' name='config_content'><?php echo $config_content;?></textarea>
				<?php 
				break;
			case 2://input type text
				?>
				<input type='text' name='config_content' value="<?php echo $config_content;?>"/>
				<?php
				break;
			case 3://textarea
				?>
				<textarea name='config_content'><?php echo $config_content;?></textarea>
				<?php
				break;
			case 4://input ckfinder
				?>
				<input name='config_content' class='finder' value='<?php echo $config_content;?>'/>
				<?php
				break;
			default:
				Common::header_location(null,'error.php?code=404');
				break;
		} 
		?>
	</label>
	<div style='text-align:right;padding:4px'>
		<input type='submit' value='Lưu' name='submit_value'/>
		<input type='submit' value='Lưu & Đóng' name='submit_value'/>		
		<input type='button' value='Đóng' id='btn_close' onclick="
			if(window.opener)
			{
				window.opener.location.reload();
				window.close();
			}
			else 
			{
				window.location='index.php';
			}
		"/>
	</div>
</form>